import { Component } from 'react';
import './BaseComponent.css'
import {Link, Redirect, Route, withRouter} from "react-router-dom";
import Home from "./page/Home/Home";
import Produck from "./page/Produck/Produck";
import Cart from "./page/Cart/Cart"
class BaseComponent extends Component{
    constructor(props) {
        super(props);

    }
    toCart(){
        // console.log(this.props.history)
        /*push 有history记录
        * replace 没有记录*/
        this.props.history.push("/cart")
    }
    render() {
        return (
            <div className="base">
                <header>
                    <Link to={"/"} >首页</Link>
                    <Link to={"/produck"} >商品</Link>
                    <button onClick={()=>this.toCart()}>购物车</button>
                </header>
                <section>
                    <Route path={"/"} exact render={()=><Redirect to={'/home'} />} ></Route>
                    <Route path={"/home"} component={Home} ></Route>
                    <Route path={"/produck"} component={Produck}></Route>
                    <Route path={"/cart"} component={Cart} ></Route>
                </section>
            </div>
        )
    }
}
export default withRouter(BaseComponent);